<%@page import="java.util.Date"%>
<%@page import="edu.scau.hibernate.model.User"%>
<%@page import="edu.scau.hibernate.service.*"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" errorPage="error.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>register</title>
<% request.setCharacterEncoding("UTF-8"); %>
</head>
<body>
   <!--注册检测  -->
  <%UserService serviceImpl = new UserServiceImpl();
    User user = new User();
    if(serviceImpl.findUserByUserName(request.getParameter("userName"))!=null){
    	throw new Error("用户名已存在！");
    }
    else if((request.getParameter("p1").equals(request.getParameter("p2")))){
    	    user.setUserName(request.getParameter("userName"));
    	    user.setPassword(request.getParameter("p1"));
    	    user.setGender(request.getParameter("gender"));
    	    user.setAge(Integer.parseInt(request.getParameter("age")));
    	    user.setEmail(request.getParameter("email"));
    	    user.setRegDatetime(new Date());
    	    session.setAttribute("user",user);//session 设置user
    	    if(serviceImpl.addUser(user)){
    	        response.sendRedirect("index.jsp");
    	        }
    }
    else
    	throw new Error("两次密码不一致！");
    	
  %>
</body>
</html>

